﻿// CUserDlg.cpp: 实现文件
//

#include "pch.h"
#include "HospitalSystem.h"
#include "CUserDlg.h"
#include "admin.h"

// CUserDlg

IMPLEMENT_DYNCREATE(CUserDlg, CFormView)

CUserDlg::CUserDlg()
	: CFormView(IDD_CUserDlg)
	, m_yhm(_T(""))
	, m_new_pwd(_T(""))
	, m_suro_pwd(_T(""))
	, m_nmae(_T(""))
{

}

CUserDlg::~CUserDlg()
{
}

void CUserDlg::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT5, m_yhm);
	DDX_Text(pDX, IDC_EDIT2, m_new_pwd);
	DDX_Text(pDX, IDC_EDIT4, m_suro_pwd);
	DDX_Text(pDX, IDC_EDIT3, m_nmae);
}

BEGIN_MESSAGE_MAP(CUserDlg, CFormView)
	ON_BN_CLICKED(IDC_BUTTON2, &CUserDlg::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON3, &CUserDlg::OnBnClickedButton3)
END_MESSAGE_MAP()


// CUserDlg 诊断

#ifdef _DEBUG
void CUserDlg::AssertValid() const
{
	CFormView::AssertValid();
}

#ifndef _WIN32_WCE
void CUserDlg::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif
#endif //_DEBUG


// CUserDlg 消息处理程序

void CUserDlg::OnInitialUpdate()
{
	//初始化界面
	CFormView::OnInitialUpdate();
	CAdmin m_set1;
	//if(m_set1.IsOpen())
	m_set1.Open();

	CString str1;
	str1 = m_set1.m_UID;
	m_nmae = str1;
	m_yhm = L"管理员";
	UpdateData(FALSE);

	// TODO: 在此添加专用代码和/或调用基类
}

void CUserDlg::OnBnClickedButton2()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(true);
	if (m_new_pwd.IsEmpty() || m_suro_pwd.IsEmpty())
	{
		MessageBox(L"输入内容不能为空！");
		return;
	}
	if (m_new_pwd != m_suro_pwd)
	{
		MessageBox(L"新密码与确定密码不能一致！");
		return;
	}
	//修改密码
	CAdmin m_set1;
	m_yhm = L"管理员";
	if (m_set1.IsOpen())
		m_set1.Close();
	m_set1.Open(CRecordset::dynamic, NULL, CRecordset::none);
	//m_set1.AddNew();
	CString str1;
	str1 = m_set1.m_PWD;
	UpdateData(true);
	if (str1 == m_new_pwd)
	{
		MessageBox(L"新密码不能与旧密码一致！");
	}
	else
	{
		if (m_set1.IsOpen())
		{
			m_set1.Edit();
			m_set1.m_PWD = m_new_pwd;
			m_set1.Update();
		}
		m_set1.Close();
		MessageBox(L"修改成功！");
		m_new_pwd.Empty();
		m_suro_pwd.Empty();
		UpdateData(FALSE); //把数据更新到控件上
	}
}




void CUserDlg::OnBnClickedButton3()
{
	m_new_pwd.Empty();
	m_suro_pwd.Empty();
	UpdateData(FALSE); //把数据更新到控件上
}
